package com.bjgov.scoresys.entity;
// default package

import static javax.persistence.GenerationType.IDENTITY;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.OrderBy;

/**
 * User entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "user", catalog = "scoresys", uniqueConstraints = @UniqueConstraint(columnNames = "LOGIN_NAME"))
public class User implements java.io.Serializable {

	// Fields

	private Integer id;
	private String loginName;
	private String realName;
	private String password;
	private Short authority;
	private Date createDate;
	private Integer loginCount;
	private Date lastLoginDate;
	private String lastLoginIp;
	private Short status;
	private String deptName;
	private Set<ScoreHistory> scoreHistories = new HashSet<ScoreHistory>(0);
	private Set<UserProject> userProjects = new HashSet<UserProject>(0);

	// Constructors

	/** default constructor */
	public User() {
	}

	/** minimal constructor */
	public User(String loginName, Short authority, Date createDate) {
		this.loginName = loginName;
		this.authority = authority;
		this.createDate = createDate;
	}

	/** full constructor */
	public User(String loginName, String realName, String password,
			Short authority, Date createDate, Integer loginCount,
			Date lastLoginDate, String lastLoginIp, Short status,
			String deptName, Set<ScoreHistory> scoreHistories,
			Set<UserProject> userProjects) {
		this.loginName = loginName;
		this.realName = realName;
		this.password = password;
		this.authority = authority;
		this.createDate = createDate;
		this.loginCount = loginCount;
		this.lastLoginDate = lastLoginDate;
		this.lastLoginIp = lastLoginIp;
		this.status = status;
		this.deptName = deptName;
		this.scoreHistories = scoreHistories;
		this.userProjects = userProjects;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "ID", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	@Column(name = "LOGIN_NAME", unique = true, nullable = false, length = 100)
	public String getLoginName() {
		return this.loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	@Column(name = "REAL_NAME", length = 100)
	public String getRealName() {
		return this.realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	@Column(name = "PASSWORD", length = 30)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name = "AUTHORITY", nullable = false)
	public Short getAuthority() {
		return this.authority;
	}

	public void setAuthority(Short authority) {
		this.authority = authority;
	}

	@Column(name = "CREATE_DATE", nullable = false, length = 19)
	public Date getCreateDate() {
		return this.createDate;
	}

	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
	}

	@Column(name = "LOGIN_COUNT")
	public Integer getLoginCount() {
		return this.loginCount;
	}

	public void setLoginCount(Integer loginCount) {
		this.loginCount = loginCount;
	}

	@Column(name = "LAST_LOGIN_DATE", length = 19)
	public Date getLastLoginDate() {
		return this.lastLoginDate;
	}

	public void setLastLoginDate(Date lastLoginDate) {
		this.lastLoginDate = lastLoginDate;
	}

	@Column(name = "LAST_LOGIN_IP", length = 100)
	public String getLastLoginIp() {
		return this.lastLoginIp;
	}

	public void setLastLoginIp(String lastLoginIp) {
		this.lastLoginIp = lastLoginIp;
	}

	@Column(name = "STATUS")
	public Short getStatus() {
		return this.status;
	}

	public void setStatus(Short status) {
		this.status = status;
	}

	@Column(name = "DEPT_NAME", length = 200)
	public String getDeptName() {
		return this.deptName;
	}

	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
	@OrderBy(clause="id desc")
	public Set<ScoreHistory> getScoreHistories() {
		return this.scoreHistories;
	}

	public void setScoreHistories(Set<ScoreHistory> scoreHistories) {
		this.scoreHistories = scoreHistories;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user")
	@OrderBy(clause="id desc")
	public Set<UserProject> getUserProjects() {
		return this.userProjects;
	}

	public void setUserProjects(Set<UserProject> userProjects) {
		this.userProjects = userProjects;
	}

}